package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id=#{id}")
    Dish byId(Long id);
    @AutoFill(type = OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, status, description, image, create_time, update_time, create_user, update_user) values " +
    "(#{name},#{categoryId},#{price},#{status},#{description},#{image},#{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Dish dish);

    void delete(List<Long> ids);
    @AutoFill(type = OperationType.UPDATE)
    void update(Dish dish);
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> list(Long categoryId);

    @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    List<Dish> byCategoryId(Dish dish);

    @Select("select count(*) from dish where status=#{i}")
    Integer byStatus(int i);
}
